package news.client;

import com.google.gwt.json.client.JSONObject;
import com.google.gwt.json.client.JSONString;
import com.google.gwt.json.client.JSONValue;

public class FieldVerifier {

	private static String getNoNull(String s){
		if(s==null)return "";
		else return s;
	}
	public static String hasHeader(JSONObject pv) {
		String header = getNoNull(pv.get("header").isString().stringValue().toString());
		if (header.length()<1) {
			return "还没有输入标题";
		}
		if (header.length() > 100) {
			return "输入标题太长";
		}
		return "";
	}
	public static String hasContent(JSONObject content) {
		String contentStr = getNoNull(content.get("content").isString().stringValue().toString());
		if (contentStr.length()<10) {
			return "还没有输入内容或内容太短";
		}		
		if (contentStr.length()>10000) {
			return "内容太长";
		}
		return "";
	}
	public static String hasType(JSONObject ws) {
		String type = getNoNull(ws.get("type").isString().stringValue()).toString();
		if (Integer.parseInt(type)<0) {
			return "还没有输入类型";
		}
		return "";
	}
}
